package br.com.pessoa.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import br.com.pessoa.Pessoa;
import br.com.pessoa.PessoaFaixada;

public class PessoaAutenticar extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public PessoaAutenticar() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		HttpSession sessao = request.getSession();
		PrintWriter out = response.getWriter();
		
		String usuario = request.getParameter("usuario");
		String senha = request.getParameter("senha");
		
		PessoaFaixada pf = new PessoaFaixada();
		Pessoa p= null;
		p = pf.autenticar(usuario, senha);
	
			// TODO Auto-generated catch block
		
		if ( p == null ){
			 response.sendRedirect("logIn.jsp");
		}
		else{
			sessao.setAttribute("funcionario", p);
			String destino = "IniciarVenda";
			response.sendRedirect (destino);
			
		}
	}
}
